--------------------------------------------- | Understanding Complicated C Declarations | --------------------------------------------- This file shows you how to decipher those complicated declarations First, A valid declaration pairs its post symbols with pre symbols, using parentheses when necessary. You can have more pre than post, but, not more post than pre symbols. That is, you must have at least one pre symbol for each post symbol for the declaration to be valid. TABLE: Symbol Text Order Direction ------------------------------------------------------- [] array of 1 Post () function returning 1 Post * pointer to 2 Pre type 3 Pre ------------------------------------------------------- OK, So what can we do with this? Lets try one! how about: char *foo[3]; Starting at the name "foo is" we see that the [] symbol has the highest order. so we insert the text. "foo is an array of 3 elements which are". And then the * comes next followed by the type. "foo is an array of 3 elements which are pointers to char. how about: char (*foo)[3]; This says "foo is a pointer to an array of 3 chars". Don't forget that the parentheses forced the precedence to the * symbol (this is not the same symbol as () refering to "function returning"). How about: int *(*(*foo[4])())[5]; Looks hard? Well following the table start at the name foo. The table states that the array symbol has precedence so we say "foo is an array of". Then the parentheses force the order to "foo is an array of pointers to". Then the () is next. "foo is an array of pointers to functions returning". Then the parentheses force the order to "foo is an array of pointers to functions returning pointers to an array of pointers to int". OK, Now lets do it the other way. Suppose we want "foo" to be "an array of 5 pointers to functions returning pointers to char" char *(*foo[5])(); You can get as complex as you want now that you know the rules. How about "foo is an array of 3 pointers to functions returning pointers to an array of 3 pointers to functions returning pointers to int"? int *(*(*(*foo[3])())[3])(); If you are like me you could not have understood this before you knew the rules that I have pointed out here. Good luck and will be "C"ing you. THE END.